package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.OrderInfoMapper;
import com.atguigu.spzx.manager.mapper.OrderStatisticsMapper;
import com.atguigu.spzx.manager.service.OrderInfoService;
import com.atguigu.spzx.model.dto.order.OrderStatisticsDto;
import com.atguigu.spzx.model.entity.order.OrderStatistics;
import com.atguigu.spzx.model.vo.order.OrderStatisticsVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

@Service
public class OrderInfoServiceImpl implements OrderInfoService {

    @Autowired
    private OrderStatisticsMapper orderStatisticsMapper;

    @Override
    public OrderStatisticsVo getOrderStatisticsData(OrderStatisticsDto timeRange) {
        //创建好结果对象
        OrderStatisticsVo orderStatisticsVo=new OrderStatisticsVo();
        orderStatisticsVo.setDateList(new ArrayList<String>());
        orderStatisticsVo.setAmountList(new ArrayList<BigDecimal>());
        //查询并遍历数据集合,封装到结果对象里
        List<OrderStatistics> list = orderStatisticsMapper.selectOrderStatisticsData(timeRange);
        for (OrderStatistics orderStatistics : list) {
            orderStatisticsVo.getDateList().add(orderStatistics.getOrderDate().toString());
            orderStatisticsVo.getAmountList().add(orderStatistics.getTotalAmount());
            //总金额的需求这里暂时没有
        }
        return orderStatisticsVo;
    }
}
